﻿#include "mcn_car_object.h"
#include <QComboBox>
#include <QGraphicsProxyWidget>
#include <QDebug>

mCN_car_object::mCN_car_object(mCN_car_object *parent)
    : MBaseObject (parent)
{
    this->setZValue(-5);
    CarNumberItem = new QGraphicsTextItem("CN***" , this);
    QFont font = CarNumberItem->font();
    font.setBold(true);
    font.setFamily("Times New Roman");
    CarNumberItem->setFont(font);
    CarNumberItem->setPos(-4,75);
    CarNumberItem->setRotation(-90);

    socketFLeft = new SocketObject(this,CarNumberItem,getCarIP());
    socketFLeft->SocketID("KFL");
    socketFLeft->socketNumber("1");
    socketFLeft->setPos(40, 70);

    socketFright = new SocketObject(this,CarNumberItem,getCarIP());
    socketFright->SocketID("KFR");
    socketFright->socketNumber("4");
    socketFright->setPos(40, 25);

    plugMleft = new PlugObject(this,CarNumberItem,getCarIP());
    plugMleft->PlugID("TML");
    plugMleft->plugNumber("2");
    plugMleft->setPos(75, 67.5);

    plugMright = new PlugObject(this,CarNumberItem,getCarIP());
    plugMright->setPos(75, 22.5);
    plugMright->PlugID("TMR");
    plugMright->plugNumber("5");
}

mCN_car_object::~mCN_car_object()
{

}

QRectF mCN_car_object::boundingRect() const
{
    return QRectF(0,0,140,90);
}

void mCN_car_object::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    Q_UNUSED(option); Q_UNUSED(widget);

    //车的外观
    QRectF squareRect_head = QRectF(0,15,20,60);
    QRectF squareRect_back = QRectF(20,0,120,90);
    QPen pen(QColor(237, 125, 49), 2, Qt::SolidLine);
    painter->setPen(pen);
    painter->drawRect(squareRect_head);
    painter->drawRect(squareRect_back);

    if(this->isSelected())
        drawSelectedRect(painter);
}
